package cn.zjjd.wlproject.hhx.demo.controller;

import cn.zjjd.wlproject.hhx.demo.config.PwdMD5;
import cn.zjjd.wlproject.hhx.demo.pojo.Admin;
import cn.zjjd.wlproject.hhx.demo.pojo.Student;
import cn.zjjd.wlproject.hhx.demo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {
    @Autowired
    private AdminService adminService;
    private PwdMD5 pwdMD5;
    @RequestMapping("/loging")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password, Model model, HttpSession session, HttpServletRequest request){
        Admin admin = new Admin();
        admin.setUsername(username);
        admin.setPassword(pwdMD5.MD5(password));
        admin = adminService.queryStudentList(admin);
        if(admin != null){
            session.setAttribute("loginUser",username);
            session.setAttribute("rightgrade",admin.getRightgrade());
            return "main";
        }else {
            model.addAttribute("msg","用户名密码错误");
            return "login";
        }
    }
}
